package com.ruoyi.project.system.vehicledriver.controller;

import java.util.List;

import com.ruoyi.project.system.vehicledriver.domain.VeVehicledriverVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.vehicledriver.domain.VeVehicledriver;
import com.ruoyi.project.system.vehicledriver.service.IVeVehicledriverService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 车辆驾驶员Controller
 * 
 * @author ruoyi
 * @date 2024-01-08
 */
@Controller
@RequestMapping("/system/vehicledriver")
public class VeVehicledriverController extends BaseController
{
    private String prefix = "system/vehicledriver";

    @Autowired
    private IVeVehicledriverService veVehicledriverService;

    @RequiresPermissions("system:vehicledriver:view")
    @GetMapping()
    public String vehicledriver()
    {
        return prefix + "/vehicledriver";
    }

    /**
     * 查询车辆驾驶员列表
     */
    @RequiresPermissions("system:vehicledriver:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VeVehicledriverVo veVehicledrivervo)
    {
        startPage();
        List<VeVehicledriverVo> list = veVehicledriverService.selectVeVehicledriverList1(veVehicledrivervo);
        return getDataTable(list);
    }

    /**
     * 导出车辆驾驶员列表
     */
    @RequiresPermissions("system:vehicledriver:export")
    @Log(title = "车辆驾驶员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VeVehicledriver veVehicledriver)
    {
        List<VeVehicledriver> list = veVehicledriverService.selectVeVehicledriverList(veVehicledriver);
        ExcelUtil<VeVehicledriver> util = new ExcelUtil<VeVehicledriver>(VeVehicledriver.class);
        return util.exportExcel(list, "车辆驾驶员数据");
    }

    /**
     * 新增车辆驾驶员
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存车辆驾驶员
     */
    @RequiresPermissions("system:vehicledriver:add")
    @Log(title = "车辆驾驶员", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VeVehicledriver veVehicledriver)
    {
        return toAjax(veVehicledriverService.insertVeVehicledriver(veVehicledriver));
    }

    /**
     * 修改车辆驾驶员
     */
    @RequiresPermissions("system:vehicledriver:edit")
    @GetMapping("/edit/{driverID}")
    public String edit(@PathVariable("driverID") Integer driverID, ModelMap mmap)
    {
        VeVehicledriver veVehicledriver = veVehicledriverService.selectVeVehicledriverByDriverID(driverID);
        mmap.put("veVehicledriver", veVehicledriver);
        return prefix + "/edit";
    }

    /**
     * 修改保存车辆驾驶员
     */
    @RequiresPermissions("system:vehicledriver:edit")
    @Log(title = "车辆驾驶员", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VeVehicledriver veVehicledriver)
    {
        return toAjax(veVehicledriverService.updateVeVehicledriver(veVehicledriver));
    }

    /**
     * 删除车辆驾驶员
     */
    @RequiresPermissions("system:vehicledriver:remove")
    @Log(title = "车辆驾驶员", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(veVehicledriverService.deleteVeVehicledriverByDriverIDs(ids));
    }
}
